<template>
  <div>
    <TypeNav />
    <ListContainer />
    <Recommend />
    <Rank />
    <Like />
    <Floor v-for="(floor) in floorList" :key="floor.id" :list="floor" />
    <Brand />
  </div>
</template>

<script>
import ListContainer from "./ListContainer";
import Recommend from "./Recommend";
import Rank from "./Rank";
import Like from "./Like";
import Brand from "./Brand";
import Floor from "./Floor";

//第四步：在组件中引入mapState辅助函数
import { mapState } from "vuex";

export default {
  components: {
    ListContainer,
    Recommend,
    Rank,
    Like,
    Brand,
    Floor,
  },
  mounted(){   
    //因为要遍历Floor组件，所以要在父组件Home中派发数据
    //第一步：在组件mounted中派发action，通知Vuex向服务器发起ajax请求获取floorList数据，将数据存储在store中
    this.$store.dispatch("getFloorList");
  },
  computed: {
    //第五步：在组件computed中，从store中读取数据
    ...mapState({
      floorList: (state) => state.home.floorList,
    }),
  },
};
</script>

<style>
</style>